#ifndef ANIMATIONDATAHANDLER_H
#define ANIMATIONDATAHANDLER_H

#include "CommonMarcro.h"
#include <QObject>
#include "action.h"
#include <QDomDocument>
#include <QDomNode>
#include <QDomProcessingInstruction>
#include <QFile>

typedef QList<Action*> ActionList;

class AnimationDataHandler : public QObject
{
    Q_OBJECT
public:
    explicit AnimationDataHandler(QObject *parent = 0);
    ~AnimationDataHandler();

    static AnimationDataHandler* instance();
    static void purgeInstance();

    bool isValidIndex(int index);  

    inline int getCurrentActionIndex() {if(m_currentAction == NULL) return -1; return m_actionList.indexOf(m_currentAction);}
    inline Action* getCurrentAction(){return m_currentAction;}
    inline Action* getActionByIndex(int index) {if (!isValidIndex(index)) return NULL; return m_actionList.at(index);}
    int getCurrenFrameIndex();
    PlistFrameInfo* getCurrentFrame();

    void appendNewActionData();
    void removeActionByIndex(int index);
    void setCurrentActionByIndex(int index);

    void setCurrentFrameByIndex(int index);
    void removeFrameByIndex(int index);
    void appendFrameList(const PlistFrameInfoList& frameList);

    inline int getActionCount() {return m_actionList.count();}

    const QDomDocument* convertToDomDocument();
    bool loadFromFile(QFile& file);

    bool clearAllData();

    void resetAll();

    void convertStringListToDom(QDomElement& element, QString attribute, QStringList& list);
    void convertDomToStringList(QDomElement& element, QString attribute, QStringList &list);


 private:
    static AnimationDataHandler* _instance;

 private:
    Action* m_currentAction;
    ActionList m_actionList;
    
signals:
    void notifyAllDataChangeUpdate();    
    void notifyActionDataChangeUpdate();
    void notifyFrameDataChangeUpdate();
    
public slots:

    
};

#endif // ANIMATIONDATAHANDLER_H
